package com.jiawa.train.business.controller.admin;

import com.jiawa.train.business.domain.DailyTrain;
import com.jiawa.train.business.domain.Req.DailyTrainQueryReq;
import com.jiawa.train.business.domain.Req.DailyTrainSaveReq;
import com.jiawa.train.business.domain.resp.DailyTrainQueryResp;
import com.jiawa.train.business.service.DailyTrainService;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.common.resp.PageResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/admin/daily-train")
public class AdminDailyTrainController {

    @Autowired
    private DailyTrainService dailyTrainService;

    @PostMapping("/save")
    public CommonResp<Object> save(@RequestBody DailyTrainSaveReq dailyTrainSaveReq) {
        dailyTrainService.save(dailyTrainSaveReq);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<DailyTrainQueryResp>> queryList(@Valid DailyTrainQueryReq dailyTrainQueryReq) {
        PageResp<DailyTrainQueryResp> queryList = dailyTrainService.queryList(dailyTrainQueryReq);
        return new CommonResp<>(queryList);
    }
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable("id") Long id) {
        dailyTrainService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/gen-daily/{date}")
    public CommonResp<Object> genDaily(@PathVariable("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailyTrainService.getDaily(date);
        return new CommonResp<>();
    }
}
